package test3_14.MyTime;

public class MyTime {
    /*
     我们可以自己实现一个时间类，来满足程序中的需要。定义名为MyTime的类
     其中应有三个整型成员：时（hour），分（minute），秒（second）
     为MyTime类定义构造方法，以方便创建对象时初始化成员变量。
     再定义display方法，用于将时间信息打印出来。
     为MyTime类添加以下方法：
     addSecond(int sec),addMinute(int min),addHour(int hou)
     subSecond(int sec),subMinute(int min),subHour(int hou)
     分别对时、分、秒进行加减运算。
     */
    int hour;
    int minute;
    int second;
    public MyTime(int hour, int minute,int second){
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }

    public void addSecond(int sec){
        //this.second += sec;
        if(this.second+sec>=60){
            this.minute += (sec+this.second)/60;
            this.second = (sec+this.second)%60;
            if(this.minute>=60){
                this.hour += this.minute/60;
                this.minute = this.minute%60;
                if (this.hour>=24){
                    this.hour %= 24;
                }
            }
        }
        //return sec;
    }
    /*
    public int addMinute(int min){
        this.minute = this.minute + min;
        if(this.minute+min>=60){
            this.hour += this.minute/60;
            this.minute = this.minute-this.minute/60*60;
            if (this.hour>24){
                this.hour %= 24;
            }
        }
        return min;
    }
     */
    public void addMinute(int min){
        addSecond(60*min);
    }

    /*
    public int addHour(int hou){
        this.hour = this.hour + hou;
        if (this.hour>=24){
            this.hour %= 24;
        }
        return hou;
    }
     */

    public void addHour(int hou){
        addSecond(hou*3600);
    }
    /*
    public int subSecond(int sec){
        this.second = this.second-sec;
        if(this.second-sec<0){
            this.minute -= 1;
            this.second = 60+this.second;
            if(this.minute<0){
                this.hour -= 1;
                this.minute = 60+this.minute-1;
                if (this.hour<0){
                    this.hour = 24+this.hour-1;
                }
            }
        }
        return sec;
    }
     */

//    public int subSecond(int sec){
//        int secTotal = this.hour*3600+this.minute*60+this.second;
//        this.hour = secTotal/3600%24;
//        secTotal -=
//        this.minute =
//    }

    public int subMinute(int min){
        this.minute = this.minute-min;
        if(this.minute<0){
            this.hour -= 1;
            this.minute = 60+this.minute;
            if (this.hour<0){
                this.hour = 24+this.hour-1;
            }
        }
        return min;
    }
    public int subHour(int hou){
        this.hour = this.hour - hou;
        if (this.hour<0){
            this.hour = 24+this.hour;
        }
        return hou;
    }

    public void display(){
        System.out.println(hour+"时"+minute+"分"+second+"秒");
    }
}
